<%@ page language="java" pageEncoding="UTF-8"
	contentType="text/html; charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort();
	String id = "1";
	String aid = request.getParameter("aid").toString();
	aid = aid.substring(0, aid.indexOf("."));
	String name = request.getParameter("name").toString();
%>
<html>
<head>
<title>调查报告</title>
<script type="text/javascript">
	//web office
	word = function() {
		var localDir = "D:/temp/"; // 本地保存的临时目录
		var docName;// 本地保存的文件名, 也为上传到服务器上时的文件名
		var docUrl; // 远程文件 e.g. http://128.96.172.238:9080/aaa/upload/aaa.doc
		var uploadUrl; // 上传到服务器的url
		var fso;
		{
			fso = new ActiveXObject("Scripting.FileSystemObject");
			if (!fso.FolderExists(localDir)) {
				fso.CreateFolder(localDir);
			}
		}
		// 打开word
		this.openDoc = function(docName, docUrl) {
			this.docName = docName;
			this.docUrl = docUrl;
			if (typeof (docUrl) == 'undefined' || docUrl == ''
					|| docUrl == null) {
				document.getElementById('WebOffice1')
						.CreateNew("Word.Document");
			} else {
				alert(docUrl);
				document.getElementById('WebOffice1').Open(docUrl, true);
			}
			document.getElementById('WebOffice1')
					.Save(localDir + docName, true);
		}

		// 打开excel--未完成
		this.openXls = function(docName, docUrl) {
			this.docName = docName;
			this.docUrl = docUrl;
			if (typeof (docUrl) == 'undefined' || docUrl == ''
					|| docUrl == null) {
				document.getElementById('WebOffice1').CreateNew("Excel.Sheet");
			} else {
				document.getElementById('WebOffice1').Open(docUrl, false);
			}
			document.getElementById('WebOffice1')
					.Save(localDir + docName, true);
		}

		this.setUploadUrl = function(uploadUrl) {
			this.uploadUrl = uploadUrl;
		}
		this.saveDoc = function() {
			document.getElementById('WebOffice1').HttpInit();
			document.getElementById('WebOffice1').HttpAddPostCurrFile(
					"FileData", this.docName);
			document.getElementById('WebOffice1').HttpPost("<%=basePath%>${ctx}/ta/stAttachment/save");
		}
		this.saveDocAndParm = function(id, docUrl) {
			try {
				var webObj = document.getElementById("WebOffice1");
				var returnValue;

				webObj.HttpInit(); //初始化Http引擎
				// 增加Post变量
				webObj.HttpAddPostString("id", id);
				webObj.HttpAddPostString("docUrl", docUrl);
				webObj.HttpAddPostCurrFile("DocContent", "");
				/* //强制保存2003
				document.getElementById('WebOffice1').WebOffice1.OptionFlag |= 0x0003; */
				returnValue = document.getElementById('WebOffice1').HttpPost("<%=basePath%>${ctx}/ta/stAttachment/save");
				if ("succeed" == returnValue) {
					alert("调查报告上传成功");
				} else if ("failed" == returnValue) {
					alert("调查报告上传失败");
				}
			} catch (e) {
				alert("异常Error:" + e);
			}

		}
		this.close = function() {
			document.getElementById('WebOffice1').close();
			try {
				fso.DeleteFile(localDir + this.docName);
			} catch (err) {
			}
		}
	}
	var word = new word();
	function load(name, url) {
		word.openDoc(name, url);
	}
	//保存文件到服务器上
	function uploadFile() {
		word.saveDocAndParm("1");
	}
</script>
</head>
<body
	onload="load('<%=name%>','http://localhost:8080/jeesite/a/ta/stAttachment/open?aid=<%=aid%>')">
	<input type="button" value="保存文件到服务器" onclick="uploadFile()">
	<hr />
	<object classid="clsid:00460182-9E5E-11d5-B7C8-B8269041DD57"
		codebase="dsoframer.CAB#Version=2.0.0.0" id="WebOffice1" width="100%"
		height="100%">
		<param name="BorderStyle" value="1">
		<param name="TitlebarColor" value="52479">
		<param name="TitlebarTextColor" value="0">
	</object>
</body>
</html>